<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>messagechannel.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_messaging_messagechannel.js.html">messagechannel.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview An interface for asynchronous message-passing channels.
<a name="line17"></a> *
<a name="line18"></a> * This interface is useful for writing code in a message-passing style that&#39;s
<a name="line19"></a> * independent of the underlying communication medium. It&#39;s also useful for
<a name="line20"></a> * adding decorators that wrap message channels and add extra functionality on
<a name="line21"></a> * top. For example, {@link goog.messaging.BufferedChannel} enqueues messages
<a name="line22"></a> * until communication is established, while {@link goog.messaging.MultiChannel}
<a name="line23"></a> * splits a single underlying channel into multiple virtual ones.
<a name="line24"></a> *
<a name="line25"></a> * Decorators should be passed their underlying channel(s) in the constructor,
<a name="line26"></a> * and should assume that those channels are already connected. Decorators are
<a name="line27"></a> * responsible for disposing of the channels they wrap when the decorators
<a name="line28"></a> * themselves are disposed. Decorators should also follow the APIs of the
<a name="line29"></a> * individual methods listed below.
<a name="line30"></a> *
<a name="line31"></a> */
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>goog.provide(&#39;goog.messaging.MessageChannel&#39;);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * @interface
<a name="line40"></a> */
<a name="line41"></a>goog.messaging.MessageChannel = function() {};
<a name="line42"></a>
<a name="line43"></a>
<a name="line44"></a>/**
<a name="line45"></a> * Initiates the channel connection. When this method is called, all the
<a name="line46"></a> * information needed to connect the channel has to be available.
<a name="line47"></a> *
<a name="line48"></a> * Implementers should only require this method to be called if the channel
<a name="line49"></a> * needs to be configured in some way between when it&#39;s created and when it
<a name="line50"></a> * becomes active. Otherwise, the channel should be immediately active and this
<a name="line51"></a> * method should do nothing but immediately call opt_connectCb.
<a name="line52"></a> *
<a name="line53"></a> * @param {Function=} opt_connectCb Called when the channel has been connected
<a name="line54"></a> *     and is ready to use.
<a name="line55"></a> */
<a name="line56"></a>goog.messaging.MessageChannel.prototype.connect = function(opt_connectCb) {};
<a name="line57"></a>
<a name="line58"></a>
<a name="line59"></a>/**
<a name="line60"></a> * Gets whether the channel is connected.
<a name="line61"></a> *
<a name="line62"></a> * If {@link #connect} is not required for this class, this should always return
<a name="line63"></a> * true. Otherwise, this should return true by the time the callback passed to
<a name="line64"></a> * {@link #connect} has been called and always after that.
<a name="line65"></a> *
<a name="line66"></a> * @return {boolean} Whether the channel is connected.
<a name="line67"></a> */
<a name="line68"></a>goog.messaging.MessageChannel.prototype.isConnected = function() {};
<a name="line69"></a>
<a name="line70"></a>
<a name="line71"></a>/**
<a name="line72"></a> * Registers a service to be called when a message is received.
<a name="line73"></a> *
<a name="line74"></a> * Implementers shouldn&#39;t impose any restrictions on the service names that may
<a name="line75"></a> * be registered. If some services are needed as control codes,
<a name="line76"></a> * {@link goog.messaging.MultiMessageChannel} can be used to safely split the
<a name="line77"></a> * channel into &quot;public&quot; and &quot;control&quot; virtual channels.
<a name="line78"></a> *
<a name="line79"></a> * @param {string} serviceName The name of the service.
<a name="line80"></a> * @param {function((string|!Object))} callback The callback to process the
<a name="line81"></a> *     incoming messages. Passed the payload. If opt_objectPayload is set, the
<a name="line82"></a> *     payload is decoded and passed as an object.
<a name="line83"></a> * @param {boolean=} opt_objectPayload If true, incoming messages for this
<a name="line84"></a> *     service are expected to contain an object, and will be deserialized from
<a name="line85"></a> *     a string automatically if necessary. It&#39;s the responsibility of
<a name="line86"></a> *     implementors of this class to perform the deserialization.
<a name="line87"></a> */
<a name="line88"></a>goog.messaging.MessageChannel.prototype.registerService =
<a name="line89"></a>    function(serviceName, callback, opt_objectPayload) {};
<a name="line90"></a>
<a name="line91"></a>
<a name="line92"></a>/**
<a name="line93"></a> * Registers a service to be called when a message is received that doesn&#39;t
<a name="line94"></a> * match any other services.
<a name="line95"></a> *
<a name="line96"></a> * @param {function(string, (string|!Object))} callback The callback to process
<a name="line97"></a> *     the incoming messages. Passed the service name and the payload. Since
<a name="line98"></a> *     some channels can pass objects natively, the payload may be either an
<a name="line99"></a> *     object or a string.
<a name="line100"></a> */
<a name="line101"></a>goog.messaging.MessageChannel.prototype.registerDefaultService =
<a name="line102"></a>    function(callback) {};
<a name="line103"></a>
<a name="line104"></a>
<a name="line105"></a>/**
<a name="line106"></a> * Sends a message over the channel.
<a name="line107"></a> *
<a name="line108"></a> * @param {string} serviceName The name of the service this message should be
<a name="line109"></a> *     delivered to.
<a name="line110"></a> * @param {string|!Object} payload The value of the message. If this is an
<a name="line111"></a> *     Object, it is serialized to a string before sending if necessary. It&#39;s
<a name="line112"></a> *     the responsibility of implementors of this class to perform the
<a name="line113"></a> *     serialization.
<a name="line114"></a> */
<a name="line115"></a>goog.messaging.MessageChannel.prototype.send =
<a name="line116"></a>    function(serviceName, payload) {};
</pre>


</body>
</html>
